package cn.psvmc.cxzapi.controller.market;

import cn.psvmc.cxzapi.model.common.*;
import cn.psvmc.cxzapi.model.market.TBrandModel;
import cn.psvmc.cxzapi.response.Result;
import cn.psvmc.cxzapi.response.ResultGenerator;
import cn.psvmc.cxzapi.service.market.TBrandModelService;
import cn.psvmc.cxzapi.util.ToolUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 基础信息-品牌型号管理
 * @Author auto
 * @Date 2024-08-13
 */
@RestController
@RequestMapping("/brand_model")
public class TBrandModelController {

    @Resource
    private TBrandModelService tBrandModelService;

    /**
    * @Author auto 2024-08-13 新增品牌型号表
    * @Param tBrandModel 品牌型号表
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/add")
    public Result add(@RequestBody TBrandModel tBrandModel) {
        ToolUtils.validation(new Object[]{tBrandModel.getModelName(), "型号名称", 1, tBrandModel.getBrandId(), "品牌id", 1});
        int addResult = tBrandModelService.add(tBrandModel);
        if (addResult > 0) {
            return ResultGenerator.genSuccessResult("保存成功！");
        }
        return ResultGenerator.genFailResult("保存失败！");
    }

    /**
    * @Author auto 2024-08-13 更新品牌型号表
    * @Param tBrandModel 品牌型号表模型
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/edit")
    public Result edit(@RequestBody TBrandModel tBrandModel) {
        ToolUtils.validation(new Object[]{tBrandModel.getBmid(), "id", 1, tBrandModel.getRversion(), "版本", 1});
        int updateResult = tBrandModelService.edit(tBrandModel);
        if (updateResult > 0) {
            return ResultGenerator.genSuccessResult("更新成功！");
        }
        return ResultGenerator.genFailResult("更新失败！");
    }

    /**
    * @Author auto 2024-08-13 删除品牌型号表
    * @Param [entity] 删除实体类
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/delete")
    public Result delete(@RequestBody DelEntity entity) {
        Integer id = entity.getId();
        Integer rversion = entity.getRversion();
        ToolUtils.validation(new Object[]{id, "id", 1, rversion, "版本", 1});
        int delResult = tBrandModelService.delete(id, rversion);
        if (delResult > 0) {
            return ResultGenerator.genSuccessResult("删除成功！");
        }
        return ResultGenerator.genFailResult("删除失败！");
    }

    /**
    * @Author auto 2024-08-13 管理列表
    * @Param entity 分页查询通用实体类
    * @Return cn.psvmc.cxzapi.response.Result
    */
    @PostMapping("/list")
    public Result list(@RequestBody DetailEntity entity) {
        ToolUtils.validation(new Object[]{entity.getId(), "品牌id", 1});
        return ResultGenerator.genSuccessResult("查询成功！", tBrandModelService.listAll(entity));
    }

    /**
     * @Description 选择列表
     * @Date 2024/8/13 9:53
     * @Author YWX
     * @Param [entity]
     * @Return cn.psvmc.cxzapi.response.Result
     **/
    @PostMapping("/list_sel")
    public Result listForSel(@RequestBody DetailEntity entity) {
        return ResultGenerator.genSuccessResult("查询成功！", tBrandModelService.listForSel(entity));
    }
}
